<?php

require_once ('code/Tasks.php');

if ((isset($_POST["projectid"])) && isset($_POST["txtTask"]) && (isset($_POST["selType"])) && (isset($_POST["operation"])) && (isset($_POST["userid"]))) {
    $task = $_POST["txtTask"];
    $type = $_POST["selType"];
    $status = $_POST["selStatus"];
    $operation = $_POST["operation"];
    $userid = $_POST["userid"];
    $projectid = $_POST["projectid"];

    $tasksObj = new Tasks();

    if ($operation == "insert") {
        // Insert
        $tasksObj->saveTask($projectid, $userid, $type, $task, $status);
    } else {
        // Update
        if (isset($_POST["taskid"])) {
            $taskid = $_POST["taskid"];
            $tasksObj->updateTask($userid, $type, $task, $status, $taskid);
        }
    }
    
    header("location: viewproject.php?projectid=" . $_POST["projectid"]);        
} else {
    echo 'Invalid request parameters !';
    error_log("Invalid request parameters !", 0);
    header('location: projects.php');
}



?>